package org.fpaadmin.web;

import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
import org.apache.wicket.IRequestCycleProvider;
import org.apache.wicket.request.cycle.RequestCycle;
import org.apache.wicket.request.cycle.RequestCycleContext;
import org.apache.wicket.protocol.http.WebApplication;

/**
 * Application object for your web application. If you want to run this
 * application without deploying, run the Start class.
 * 
 * @see br.gov.anac.Start#main(String[])
 */
public class FpaAdminApplication extends WebApplication {
    
    private EntityManagerFactory emf;

    public EntityManagerFactory getEntityManagerFactory() {
	return this.emf;
    }

    /**
     * Constructor
     */
    public FpaAdminApplication() {
    }

    /**
     * @see org.apache.wicket.Application#getHomePage()
     */
    public Class<HomePage> getHomePage() {
	return HomePage.class;
    }

    @Override
    public void init() {
	super.init();
	this.emf = Persistence.createEntityManagerFactory("dbmanager");
	this.setRequestCycleProvider(new IRequestCycleProvider() {
	    public RequestCycle get(RequestCycleContext context) {
		return new JpaRequestCycle(emf, context);
	    }
	});
    }

}
